package cn.edu.hbwe.book.admin.service.books;

import java.sql.SQLException;
import java.util.List;

import cn.edu.hbwe.book.admin.dao.BookDao;
import cn.edu.hbwe.book.entity.Book;
import cn.edu.hbwe.book.exception.AddBookException;

public class BooksService {
	private BookDao dao = new BookDao();

	// 查询所有的图书
	public List<Book> listAll() {
		List<Book> lb;
		try {
			lb = dao.listAll();
			return lb;
		} catch (SQLException e) {

			e.printStackTrace();
			throw new RuntimeException("查询商品失败!");
		}

	}

	// 根据条件查询图书
	public List<Book> findBookCondition(String id, String name, String category, String minprice, String maxprice) {
		try {
			List<Book> lb = dao.finBookCondition(id, name, category, minprice, maxprice);
			return lb;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	// 添加图书数据
	public void addBook(Book b) throws AddBookException {
		try {
			dao.addBook(b);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new AddBookException("添加失败！");
		}
	}

	// 根据id删除图书信息
	public void deleteBook(String id) {
		try {
			dao.deleteBook(id);
		} catch (SQLException e) {
			throw new RuntimeException("删除商品信息失败！");
		}
	}

	// 修改图书信息
	public void editBook(Book b) {
		try {
			dao.editBook(b);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	// 下载销售榜单
	public List<Object[]> infoDownload(String year, String month) {
		List<Object[]> salesList = null;
		try {
			salesList = dao.salesList(year, month);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return salesList;
	}
}
